package com.hfzy.ihk.web.aliyuncall.context;

import com.hfzy.ihk.common.util.http.HttpClientUtils;
import com.hfzy.ihk.common.util.string.StringUtil;
import com.hfzy.ihk.facade.websocket.linkcall.service.WebSocketService;
import com.hfzy.ihk.web.aliyuncall.constant.Constants;
import com.hfzy.ihk.web.aliyuncall.constant.PublicConfig;
import com.hfzy.ihk.web.aliyuncall.constant.RedisKey;
import com.hfzy.ihk.web.aliyuncall.support.SampleMemoryCache;
import com.hfzy.ihk.web.aliyuncall.support.websocket.WebSocketUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.context.WebApplicationContext;

import java.util.Set;

/**
 * 描述:获取spring上下文
 *Spring动态注册rmi bean
 */
@Component
public class CloudCallInitializingBean implements ApplicationContextAware {

    @Autowired
    RedisTemplate redisTemplate;




    private static ApplicationContext ctx;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext)
            throws BeansException {

        CloudCallInitializingBean.ctx = applicationContext;

        initUtils();

    }

    public void initUtils(){
//


    }

    public static ApplicationContext getApplicationContext(){
        return ctx;
    }

    public static String getRealPath(String path){
        return ((WebApplicationContext)ctx).getServletContext().getRealPath(path);
    }


    /**
     * 初始化客户投诉号码列表
     */
    private void initBadCustomerMap(){


        Set<String> badCustomerPhones = redisTemplate.opsForSet().members(RedisKey.BAD_CUSTOMER_PHONE);

        if(badCustomerPhones==null || badCustomerPhones.isEmpty())
            return;

        System.out.println(StringUtil.strConnect("badCustomerPhone size:",String.valueOf(badCustomerPhones.size())));

        for(String phone : badCustomerPhones){
            SampleMemoryCache.badCustomerPhoneMap.put(phone, Constants.TRUE);
        }

    }
}